home *** CD-ROM | disk | FTP | other *** search
/ Knitting Made Easy / Knitting.iso / App / Patterns.dxr / behaviors_94_Video Slider.ls < prev    next >
Encoding:
Text File  |  2002-04-18  |  5.6 KB  |  153 lines

  1. property pDuration, pMovieTime, videoSprite, horizontal, extentSprite, hiliteMember, tracking, newLocH, newLocV, sending, dynamic, style, Addressee, name, notify_list, min, max, valrange, minScreen, maxScreen, currentScreenVal, extentlength, CurrentVal
  2.  
  3. on getPropertyDescriptionList
  4.   if the currentSpriteNum = 0 then
  5.     memdefault = 0
  6.   else
  7.     memref = the member of sprite the currentSpriteNum
  8.     memdefault = member(member(memref).memberNum + 1)
  9.   end if
  10.   description = [:]
  11.   addProp(description, #videoSprite, [#default: 1, #format: #integer, #comment: "Video Sprite:"])
  12.   addProp(description, #extentSprite, [#default: 1, #format: #integer, #comment: "Extent Sprite:"])
  13.   addProp(description, #hiliteMember, [#default: memdefault, #format: #graphic, #comment: "Hilite Member:"])
  14.   addProp(description, #horizontal, [#default: 1, #format: #boolean, #comment: "Horizontal (if not vertical):"])
  15.   addProp(description, #dynamic, [#default: 1, #format: #boolean, #comment: "Dynamic:"])
  16.   return description
  17. end
  18.  
  19. on getBehaviorDescription
  20.   return "Drag to slider 'handle' to enable control of video play time.  Requires additional 'extent' member which limits the handle travel range." & RETURN & "PARAMETERS:" & RETURN & "ΓÇó Video Sprite - Enter the number of sprite channel in which video is displayed." & RETURN & "ΓÇó Extent Sprite -  Enter the number of sprite channel that contains the 'extent' sprite." & RETURN & "ΓÇó Hilite Member -  Member to display while handle is being dragged." & RETURN & "ΓÇó Horizontal - If set, orient extent sprite horizontally, if not set orient vertically." & RETURN & "ΓÇó Dynamic - If set, video time will be updated while handle is dragged, else when handle is released."
  21. end
  22.  
  23. on compute_val me
  24.   val = 0.0
  25.   val = float(me.currentScreenVal) / float(me.extentlength)
  26.   val = val * me.valrange
  27.   val = val + me.min
  28.   return val
  29. end
  30.  
  31. on send_the_val me, val
  32.   pMovieTime = val * pDuration
  33.   videoseek(sprite(videoSprite), pMovieTime)
  34. end
  35.  
  36. on beginSprite me
  37.   pDuration = sprite(videoSprite).duration
  38.   me.min = 0.0
  39.   me.max = 1.0
  40.   me.sending = 1
  41.   handle = me.spriteNum
  42.   me.tracking = 0
  43.   me.newLocH = the locH of sprite handle
  44.   me.newLocV = the locV of sprite handle
  45.   if me.horizontal then
  46.     me.newLocV = the locV of sprite me.extentSprite
  47.     me.minScreen = the left of sprite me.extentSprite
  48.     me.maxScreen = the right of sprite me.extentSprite
  49.   else
  50.     me.newLocH = the locH of sprite me.extentSprite
  51.     me.minScreen = the left of sprite me.extentSprite
  52.     me.maxScreen = the right of sprite me.extentSprite
  53.   end if
  54.   set the locH of sprite handle to me.newLocH
  55.   set the locV of sprite handle to me.newLocV
  56.   me.valrange = me.max - me.min
  57.   me.extentlength = me.maxScreen - me.minScreen
  58.   if me.sending = 0 then
  59.     me.dynamic = 0
  60.   end if
  61. end
  62.  
  63. on prepareFrame me
  64.   if tracking then
  65.     handle = me.spriteNum
  66.     extent = me.extentSprite
  67.     if me.horizontal then
  68.       me.newLocH = the mouseH
  69.       me.newLocV = the locV of sprite extent
  70.       if me.newLocH < the left of sprite extent then
  71.         me.newLocH = the left of sprite extent
  72.       end if
  73.       if me.newLocH > the right of sprite extent then
  74.         me.newLocH = the right of sprite extent
  75.       end if
  76.       me.currentScreenVal = me.newLocH - me.minScreen
  77.     else
  78.       me.newLocH = the locH of sprite extent
  79.       me.newLocV = the mouseV
  80.       if me.newLocV < the top of sprite extent then
  81.         me.newLocV = the top of sprite extent
  82.       end if
  83.       if me.newLocV > the bottom of sprite extent then
  84.         me.newLocV = the bottom of sprite extent
  85.       end if
  86.       me.currentScreenVal = me.newLocV - me.minScreen
  87.     end if
  88.     set the locH of sprite handle to me.newLocH
  89.     set the locV of sprite handle to me.newLocV
  90.     if me.dynamic then
  91.       send_the_val(me, compute_val(me))
  92.     end if
  93.   else
  94.     x = float(sprite(videoSprite).currentTime) / float(pDuration)
  95.     handle = me.spriteNum
  96.     extent = me.extentSprite
  97.     if me.horizontal then
  98.       ScreenX = the left of sprite extent + (x * (the right of sprite extent - the left of sprite extent))
  99.       me.newLocH = ScreenX
  100.       me.newLocV = the locV of sprite extent
  101.       if me.newLocH < the left of sprite extent then
  102.         me.newLocH = the left of sprite extent
  103.       end if
  104.       if me.newLocH > the right of sprite extent then
  105.         me.newLocH = the right of sprite extent
  106.       end if
  107.       me.currentScreenVal = me.newLocH - me.minScreen
  108.     else
  109.       ScreenY = the top of sprite extent + (x * (the bottom of sprite extent - the top of sprite extent))
  110.       me.newLocH = the locH of sprite extent
  111.       me.newLocV = ScreenY
  112.       if me.newLocV < the top of sprite extent then
  113.         me.newLocV = the top of sprite extent
  114.       end if
  115.       if me.newLocV > the bottom of sprite extent then
  116.         me.newLocV = the bottom of sprite extent
  117.       end if
  118.       me.currentScreenVal = me.newLocV - me.minScreen
  119.     end if
  120.     set the locH of sprite handle to me.newLocH
  121.     set the locV of sprite handle to me.newLocV
  122.   end if
  123. end
  124.  
  125. on mouseDown me
  126.   tracking = 1
  127.   temp = the member of sprite me.spriteNum
  128.   set the member of sprite the spriteNum of me to member(me.hiliteMember)
  129.   me.hiliteMember = temp
  130. end
  131.  
  132. on mouseUp me
  133.   tracking = 0
  134.   temp = the member of sprite me.spriteNum
  135.   set the member of sprite the spriteNum of me to member(me.hiliteMember)
  136.   me.hiliteMember = temp
  137.   if me.sending then
  138.     x = compute_val(me)
  139.     send_the_val(me, x)
  140.   end if
  141. end
  142.  
  143. on mouseUpOutSide me
  144.   tracking = 0
  145.   temp = the member of sprite me.spriteNum
  146.   set the member of sprite the spriteNum of me to member(me.hiliteMember)
  147.   me.hiliteMember = temp
  148.   if me.sending then
  149.     x = compute_val(me)
  150.     send_the_val(me, x)
  151.   end if
  152. end
  153.